#ifndef MUTEX_BUFFER_POOL_HDIFHD
#define MUTEX_BUFFER_POOL_HDIFHD

#include <stdlib.h>
#include <semaphore.h>

typedef struct mutex_buffer_pool
{
    char** buffer_array;
    size_t* real_size_array;
    sem_t** sem_array;              // buffer_count * user_count
    unsigned int* user_index_array; // user 当前所用第几格缓冲区

    size_t single_buffer_size;
    unsigned int buffer_count;
    unsigned int user_count;
}mutex_buffer_pool;

/* 创建一个互斥多格缓冲池 */
mutex_buffer_pool* new_mutex_buffer_pool
(unsigned int user_count, size_t single_buffer_size, unsigned int buffer_count);

void destroy_mutex_buffer_pool(mutex_buffer_pool* pool);

char* get_buffer(mutex_buffer_pool* pool, unsigned int user);

/* 设置 user 当前所用缓冲区的实际数据大小 */
void assign_size(mutex_buffer_pool* pool, unsigned int user, size_t real_size);

/* 获取 user 当前所用缓冲区的实际数据大小 */
size_t get_real_size(mutex_buffer_pool* pool, unsigned int user);

void release_buffer(mutex_buffer_pool* pool, unsigned int user);

#endif